<?php
class Answer_Component_Controller_Index extends Phpfox_Component
{
    public function process()
    {
		unset($_SESSION['point']);
		$_SESSION['point'] = 0;
        $sLink = "answer";
        if ($iId = $this->request()->getInt('delete')) {
            Phpfox::getService('answer.question')->delete($iId);
                        $this->url()->send($sLink, array(), Phpfox::getPhrase('answer.delete_a_question_successfully'));
        }

		$categories = Phpfox::getService('marketplace.category')->getForBrowse();
		foreach($categories as $key=>$cat){
			reset($arrEx);
			$endName = '';
			$arrEx = array();
			if($cat['name'][0]=='{'){
				$arrEx = explode("var=",$cat['name']);
				$endName = substr($arrEx[1], 6, -7);
				$categories[$key]['name'] = Phpfox::getPhrase($endName);
			}
		}
		$this->template()->assign(array(
					'categories' => $categories)
		);
				
        Phpfox::getService('answer.question')->getSectionMenu();

        //$aCondition = array('featured = 1');
        //$aFeaturedQuestions = Phpfox::getService('answer.question')->getListNoPage('q.*', $aCondition);
		// number of question 50
        $aCondition = array();
        $aPopularQuestions = Phpfox::getService('answer.question')->getListNoPage('q.*, q.image as question_image', $aCondition, 'RAND()', 2);
		//$aPopularQuestions2 = Phpfox::getService('answer.question')->getListNoPage('q.*, q.image as question_image', $aCondition,'RAND()',500);
		$aCount = Phpfox::getService('answer.question')->countQ();
		$rand = rand(1,99999);
		if($rand%2==0){
			$random = 1;
		}else{
			$random = 2;
		}
        //$aCondition = array();
        //$aRecentQuestions = Phpfox::getService('answer.question')->getListNoPage('q.*', $aCondition, 'time_stamp desc', 8);
		$homelink =$this->url()->makeUrl();
		$arrHomelink = explode('index.php',$homelink);
		$baseurl = $arrHomelink[0];
        $this->template()
            ->setTitle(Phpfox::getPhrase('answer.answer'))
            ->setBreadcrumb(Phpfox::getPhrase('answer.answers'), $this->url()->makeUrl('answer'))
            ->setHeader(array(
            '<!--[if IE]><script src="http://www.responsivejqueryslider.com/js/excanvas.compiled.js" type="text/javascript"></script><![endif]-->',
            'answer.css' => 'module_answer',
            'allinone_contentSlider.js' => 'module_answer',
            'slide.css' => 'module_answer',
            'actions.js' => 'module_answer',
            'comment.css' => 'style_css',
            'feed.js' => 'module_feed'
        ))
            ->assign(array(
            //'aFeaturedQuestions' => $aFeaturedQuestions['data'],
            'aPopularQuestions' => $aPopularQuestions['data'],
			'random' => $random,
			'baseurl' => $baseurl,
			'countQ' => $aCount[0]['number']
            //'aRecentQuestions' => $aRecentQuestions['data']
        ));
		if(Phpfox::getUserId()==4){
			$this->template()->setHeader(array('admin.css' => 'module_answer'));
		}

    }
}